puts "Hello World!"
puts "你好，世界！"

print <<EOF
	这是第一种方式创建here document。
EOF

print <<"EOF"
	这是第二种方式创建here document。
	多行字符串
EOF

print <<'EOC'
	echo hi there
	echo lo there
EOC

print <<"foo", <<"bar"
	I said foo.
foo
	I said bar.
bar

puts "这是主 Ruby 程序"

END {
   puts "停止 Ruby 程序"
}
BEGIN {
   puts "初始化 Ruby 程序"
}

name = "Madisetti" # 这也是注释

=begin
	这是注释。
	这也是注释。
	这也是注释。
	这还是注释。	
=end

a1=0
a2=1_000_000
a3=0xa

puts a1,a2
puts a3

a4=123.4
a5=1.0e6
a6=4e20
a7=4e+20
puts a4,a5,a6,a7

f1=0.0
f2=2.1
f3=1000000.1
puts f1,f2,f3

puts 2**(1/4)

puts 16**(1/4.0)

puts 'escape using "\\"'

puts 'That\'s right';

puts "相乘：#{24*60*60}"

name="Ruby"
puts name
puts "#{name +",ok"}"
puts "\n\r\f\b\a\e\s"

ary = ["fred",10,3.14,"This is a string","last element",]
ary.each do |i|
	puts i
end

hsh = colors = {"red" => 0xf00,"green"=>0x0f0,"blue"=>0x00f}
hsh.each do |key,value|
	print key," is ", value, "\n"
end

(1..1000).each do |n|
	print n, ' '
end
puts "\n"

class Customer
	@@no_of_customers=0
	def initialize(id,name,addr)
		@id, @name, @addr = id,name,addr
	end

	def hello
		puts @id
		puts @name
		puts @addr
	end
end

cust1=Customer.new("1","John","Wisdom Apartments,Ludhiya")
cust2=Customer.new("2","Poul","New Empire road, Khandala")
cust1.hello
cust2.hello

class Example
	VAR1 = 100
	VAR2 = 200
	def show
		puts "第一个常量的值为 #{VAR1}"
		puts "第二个常量的值为 #{VAR2}"
	end
end

object = Example.new()
object.show()
a = 10
b = 20
c = 30
d = a
e= 0
puts "#{a + b}"
puts "#{a - b}"
puts "#{a * b}"
puts "#{a / b}"
puts "#{a % b}"
puts "#{a ** b}"
puts "#{a == b}"
puts "#{a != b}"
puts "#{a > b}"
puts "#{a < b}"
puts "#{a >= b}"
puts "#{a <= b}"
puts "#{a <=> b}"
puts "#{(1..10) === 5}"

puts "#{1.eql?(1.0)}"

puts "#{a.equal?d}"

e = a + b
puts "#{e}"
e = c += a
puts "#{e}"
e = c -= a
puts "#{e}"
e = c *= b
puts "#{e}"
e = c /= b
puts "#{e}"
e = c %= b
puts "#{e}"
e = c **= b
puts "#{e}"

a =0b0111100
b =0b0001101

e = a&b
e = e.to_s(2)
puts "#{e}"
e = a|b
puts "#{e}"
e = ~a 
puts "#{e}"

puts "%0b" % 225

puts "#{e}"

puts 1000.to_s(14)

puts 240.to_s(2)

puts (a << 2).to_s(2)
puts (a >> 2).to_s(2)

a = 10
b = 20
e = (a and b)
puts e
e = (a or b)
puts e

e = (a && b)
puts e

e = a || b
puts e
e = !(a && b)
puts e

puts not(a && b)

puts a > b ?a:b

(1..10).each do |i|
	print i,' '
end
print "\n"
(1...10).each do |i|
	print i,' '
end
print "\n"

foo = 42
puts defined? foo
puts defined? $_
puts defined? bar

puts defined? method_call

puts defined? puts
puts defined? puts(bar)
puts defined? unpack

puts defined? supper

puts defined? yield

MR_COUNT = 0
module Foo
	MR_COUNT = 0
	::MR_COUNT = 1
	MR_COUNT = 2
end

puts MR_COUNT
puts Foo::MR_COUNT

CONST = ' out there'
class Inside_one
   CONST = proc {' in there'}
   def where_is_my_CONST
      ::CONST + ' inside one'
   end
end
class Inside_two
   CONST = ' inside two'
   def where_is_my_CONST
      CONST
   end
end
puts Inside_one.new.where_is_my_CONST
puts Inside_two.new.where_is_my_CONST
puts Object::CONST + Inside_two::CONST
puts Inside_two::CONST + CONST
puts Inside_one::CONST
puts Inside_one::CONST.call + Inside_two::CONST

x = 1
if x > 2
	puts "x 大于 2"
elsif x <= 2 and x!=0
	puts "x是1"
else
	puts "无法得知x的值"
end

$debug =1;
print "debug\n" if $debug
x=1
unless x > 2
	puts "x小于2"
 else
 	puts "x小于2"
end

$var = 1;
print "1 -- 这一行输出\n" if $var
print "2 -- 这一行不输出\n" unless $var

$var = false
print "3 -- 这一行不输出\n" unless $var

$age = 5
case $age
when 0 .. 2
	puts "婴儿"
when 3 .. 6
	puts "小孩"
when 7 .. 12
	puts "少年"
else
	puts "其他年龄段的"
end
